package com.bawei.library_image

/**
 * @Author : yaotianxue
 * @Time : On 2023/6/20 15:28
 * @Description : ImageOptions图片参数设置：构建者设计模式
 */
class ImageOptions(
    var placeImage:Int,//占位符
    var errorImage:Int,//错误图
    var isStaticImage:Boolean,//是否为静态图片
    var isGif:Boolean,//是否为动图
    var imageSize:Array<Int>,//图片大小
    var skipMemoryCache:Boolean,//关闭内存缓存
    var skipDiskCache:Boolean,//关闭磁盘缓存
    var imageCrop:ImageCrop//裁剪方式

) {
    //次构造必须继承主构造
    constructor(builder: Builder):this(
        builder.placeImage,
        builder.errorImage,
        builder.isStaticImage,
        builder.isGif,
        builder.imageSize,
        builder.skipMemoryCache,
        builder.skipDiskCache,
        builder.imageCrop
    )





    class Builder{
        var placeImage:Int = 0//占位符
        var errorImage:Int = 0 //错误图
        var isStaticImage:Boolean = true//是否为静态图片
        var isGif:Boolean = false//是否为动图
        var imageSize:Array<Int> = arrayOf(0,0)//图片大小
        var skipMemoryCache:Boolean = false//关闭内存缓存
        var skipDiskCache:Boolean = false//关闭磁盘缓存
        var imageCrop:ImageCrop = ImageCrop.CENTER //裁剪方式


        //圆形 圆角 普通
        fun  setImageCrop(imageCrop:ImageCrop):Builder{
            this.imageCrop = imageCrop
            return this
        }

        fun  setPlaceImage(placeImage:Int):Builder{
            this.placeImage = placeImage
            return this
        }
        fun  setErrorImage(errorImage:Int):Builder{
            this.errorImage = errorImage
            return this
        }
        fun  setStaticImage(isStaticImage:Boolean):Builder{
            this.isStaticImage = isStaticImage
            return this
        }
        fun  setGif(isGif:Boolean):Builder{
            this.isGif = isGif
            return this
        }

        fun  setImageSize(imageSize:Array<Int>):Builder{
            this.imageSize = imageSize
            return this
        }

        fun  setSkipMemoryCache(skipMemoryCache:Boolean):Builder{
            this.skipMemoryCache = skipMemoryCache
            return this
        }

        fun  setSkipDiskCache(skipDiskCache:Boolean):Builder{
            this.skipDiskCache = skipDiskCache
            return this
        }

        fun build():ImageOptions{
            return ImageOptions(this)
        }


    }
}